import Editor from '@/libs/svgEditor';

// 获取单一元素的背景颜色
export const getElementColor = (ele: Element, attrs: string[]) => {
  return attrs.map(attr => ele.getAttribute(attr) || '#000');
}

const setEditorColor = (editor: Editor, type: string, color: string) => {
  editor.svgCanvas.setPaint(type, {
    alpha: 100,
    type: 'solidColor',
    solidColor: color.replace('#', ''),
  });
}

//设置 editor 元素的填充颜色
export const setEditorFillColor = (editor: Editor, color: string) => {
  setEditorColor(editor, 'fill', color);
}

//设置 editor 元素的边框颜色
export const setEditorStrokeColor = (editor: Editor, color: string) => {
  setEditorColor(editor, 'stroke', color);
}

export const setShapePath = (editor: Editor, path: string) => {
  editor.svgCanvas.shapeLibPath = path;
}

export const getShapePath = (editor: Editor) => {
  return editor.svgCanvas.shapeLibPath;
}

export const clearShapePath = (editor: Editor) => {
  setShapePath(editor, '');
}
